<template>
  <div class="app-container">
    <el-card shadow="never" class="mb20">
      <div class="filter-container">
        <el-row>
          <el-col :span="20">
            <div class="filter-item">
              <label class="radio-label">回溯名称：</label>
              <el-input v-model="listQuery.dataBacktrackName" clearable placeholder="回溯名称" style="width: 200px;"  @keyup.enter.native="handleFilter" />
            </div>
            <el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter"></el-button>
            <el-button class="filter-item" icon="el-icon-refresh-left" @click="handleReset"></el-button>
          </el-col>
          <el-col :span="4" style="text-align: right;">
            <el-button class="filter-item" type="primary" icon="el-icon-plus" title="新建回溯" @click="handleAdd"></el-button>
          </el-col>
        </el-row>
      </div>
    </el-card>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      row-key="id"
      border
      stripe
      fit
      highlight-current-row>
      <el-table-column prop="dataBacktrackName" label="回溯名称" min-width="200" align="center">
      </el-table-column>
      <el-table-column prop="stepNum" label="回溯步数" min-width="100" align="center">
      </el-table-column>
      <el-table-column align="center" label="创建时间" min-width="100">
        <template slot-scope="scope">
          <span>{{ scope.row.deployTime | moment('YYYY-MM-DD HH:mm:ss') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" circle icon="el-icon-edit" title="修改" @click="handleEdit(scope.row)"></el-button>
          <el-button type="danger" size="mini" circle icon="el-icon-delete" title="删除" @click="handleRemove(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="fetchData" />
  </div>
</template>

<script>
import { getPageList, remove } from '@/api/workflow/backtrack'
import Pagination from '@/views/workflow/components/Pagination'

export default {
  components: { 
    Pagination
  },
  data() {
    return {
      total: 0,
      listQuery: {
        dataBacktrackName: undefined,
        pageNo: 1,
        pageSize: 10
      },
      list: [],
      listLoading: false
    }
  },
  filters: {},
  created() {
    this.fetchData()
  },
  methods: {
    handleFilter() {
      this.listQuery.pageNo = 1
      this.fetchData()
    },
    handleReset() {
      this.listQuery.dataBacktrackName = ''
      this.handleFilter()
    },
    fetchData() {
      // this.listLoading = true
      getPageList(this.listQuery).then(response => {
        this.total = response.data.total
        this.list = response.data.records
        this.listLoading = false
      })
    },
    handleAdd() {
      this.$router.push({ name: 'backtrackSet' })
    },
    handleEdit(row) {
      this.$router.push({ name: 'backtrackSet', query: { id: row.dataBacktrackId }})
    },
    handleRemove(row) {
      const _this = this
      this.$confirm({
        title: '提示',
        content: `您确定删除[${row.dataBacktrackName}]这条记录吗？`,
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        centered: true,
        onOk() {
          remove(row.id).then(res => {
            _this.$message.success('删除成功')
            _this.handleFilter()
          })
        }
      })
    },
  }
}
</script>
